<template>
  <el-drawer v-model="drawerShow" :title="type === 'record' ? '举报记录' : '我要举报'" direction="rtl" size="560"
    class="report-popup" @close="close">
    <div class="main">
      <no-data v-if="list.length === 0 && type === 'record'" :paddingTop="260"></no-data>

      <div v-if="type === 'form'" class="form">
        <div class="form-title font-14">举报主题</div>
        <div class="tags flex-between">
          <p v-for="item in tags" :key="item.id" class="pointer font-14" :class="{ active: item.id === form.tag }">{{
            item.name }}
          </p>
        </div>
        <el-input v-model="form.theme" type="textarea" maxlength="50" show-word-limit :rows="6"
          placeholder="还有什么要补充，可以写在这里" class="form-input" />
        <div class="form-title font-14">问题描述</div>
        <el-input v-model="form.desc" type="textarea" maxlength="500" show-word-limit :rows="6" placeholder="请详细描述问题"
          class="form-input" />
        <div class="form-title font-14">相关凭证</div>
        <el-upload v-model:file-list="form.imgs" :limit="9" action="https://run.mocky.io/v3/9d059bf9-4660-45f2-925d-ce80ad6c4d15"
          list-type="picture-card" :on-preview="handlePictureCardPreview" :on-remove="handleRemove">
          <el-icon>
            <Plus />
          </el-icon>
        </el-upload>
      </div>
    </div>
    <div class="footer flex flex-align-items-center">
      <p v-if="type === 'record'" class="font-14 pointer" @click="typeChange">我要举报</p>
      <p v-if="type === 'form'" class="font-14 pointer">提交</p>
      <p v-if="type === 'form'" class="font-14 pointer" @click="typeChange">取消</p>
    </div>
  </el-drawer>
</template>

<script setup>
import { defineProps, ref, watch, defineEmits } from 'vue';
import NoData from '@/components/noData.vue';
const props = defineProps(['show']);
const emit = defineEmits(['close']);

const drawerShow = ref(props.show);
const type = ref('record');
const tags = ref([
  {
    name: '延期交付',
    id: 1
  },
  {
    name: '收到样品后失联',
    id: 2
  },
  {
    name: '未发布视频',
    id: 3
  },
  {
    name: '交付质量差',
    id: 4
  }
]);
const list = ref([]);
const form = ref({
  tag: null,
  theme: '',
  desc: '',
  imgs: []
});
const dialogVisible = ref(false);

const typeChange = () => {
  type.value = type.value === 'record' ? 'form' : 'record';
}
const handleRemove = (uploadFile, uploadFiles) => {
  console.log(uploadFile, uploadFiles)
}

const handlePictureCardPreview = (uploadFile) => {
  form.value.img = uploadFile.url
  dialogVisible.value = true
}
const close = () => {
  emit('close');
}

watch(props, newValue => {
  drawerShow.value = newValue.show;
  type.value = 'record';
});
</script>

<style lang="less">
.report-popup {
  .el-drawer__header {
    padding-top: 0 !important;
    height: 50px;
    align-items: center;
    border-bottom: 1px solid #dcdee0;
    margin-bottom: 0 !important;

    span {
      color: #333;
      font-size: 14px !important;
      font-weight: bold;
    }
  }
}
</style>
<style lang="less" scoped>
.main {
  height: calc(100vh - 160px);
}

.form {
  .form-title {
    color: #333;
    margin-bottom: 10px;
  }

  .tags {
    margin-bottom: 8px;

    p {
      width: 122px;
      height: 34px;
      text-align: center;
      line-height: 32px;
      color: #333;
      background: #f8f8f8;
      border-radius: 6px;
      border: 1px solid #e2e2e2;

      &.active {
        border-color: #f85277;
        color: #f85277;
        background: rgba(255, 82, 119, .1);
      }
    }
  }

  .form-input {
    margin-bottom: 24px;
  }
}

.footer {
  position: absolute;
  left: 0;
  bottom: 0;
  width: 100%;
  height: 72px;
  padding-right: 24px;
  justify-content: end;
  flex-direction: row-reverse;
  background: #fff;
  box-shadow: 0 -2px 8px 0 rgba(0, 0, 0, .04);

  p {
    padding: 0 20px;
    border-radius: 10px;
    height: 40px;
    line-height: 38px;
    border: 1px solid;
    margin-left: 10px;

    &:nth-child(1) {
      color: #fff;
      background: @main-color;
      border-color: @main-color;

      &:hover {
        border-color: #ff7592;
        background-color: #ff7592;
      }
    }

    &:nth-child(2) {
      border-color: #dcdfe6;
      color: #606266;

      &:hover {
        color: @main-color;
        border-color: #ffcbd6;
        background-color: #ffeef1;
      }
    }
  }
}
</style>
